//var jsonHost = 'http://168.40.105.84:88/trainingj/';
var jsonHost = 'http://trainingj.javaxpoint.cloudbees.net/';
$(document).ready(function(){
	getWaitLists();
	var refreshId = setInterval( function(){
		onChange1();
    },5000);
});
function regMe(){
	var name = $('#name').val();
	if(name=='')return;
	var sel1 = $('#sel1').val();
	$.getJSON(jsonHost+'102?func=?&id='+sel1+"&name="
		+name+"&email=test@gmail.com",function(data) {
		if(data=='ok'){
			$('#name').val('');
			onChange1();
		}
	});
}
function removeNext(){
	var sel1 = $('#sel1').val();
	$.getJSON(jsonHost+'103?func=?&id='+sel1,function(data) {
		if(data=='ok'){
			onChange1();
		}
	});
}
function onChange1(){
	var sel1 = $('#sel1').val();
	$('#ta1').html('');
	if(sel1=='x'){
		$('#div1a').hide();
		$('#div2').hide();
		$('#div3').hide();
		return;
	}
	getWaitCusts();
}
function getWaitLists(){
	$.getJSON(jsonHost+'100?func=?', function(data) {
		var s = "<select id='sel1' onchange='onChange1();'><option value='x'>Select</option>";
		$.each(data, function (index, value) {
			var pair  = value.split(':');
	    	s += "<option value='" + pair[0] + "'>" +pair[1] + "</option>";
		});
		$('#div1').html(s+"</select>");
		$('#div1').append(
			"<div id='div1a' style='display:none;'><input type='button' value='Remove Next Customer' onclick='removeNext();'/></div>");
	});
}
function getWaitCusts(){
	var sel1 = $('#sel1').val();
	$('#custList').remove();
	$.getJSON(jsonHost+'101?func=?&id='+sel1, function(data) {
		var s = "<ul style='overflow:auto;height:100px; width:180px'>";
		$.each(data, function (index, value) {
			s += '<li>'+value+'</li>';
		});
		$('#div1a').show();
		$('#div2').show();
		$('#div3').show();
		$('#div2a').html(s+"</ul>");
	});
}
